package com.razorthink.shell.test;

import java.io.File;

import com.razorthink.shell.commands.essential.CD;
import com.razorthink.shell.commands.essential.Dashboard;
import com.razorthink.shell.commands.essential.GenDoc;
import com.razorthink.shell.commands.essential.LS;
import com.razorthink.shell.commands.essential.Login;
import com.razorthink.shell.commands.essential.Logout;
import com.razorthink.shell.commands.essential.ShowUsers;
import com.razorthink.shell.core.Application;

public class Main {
	public static void main(String[] a) throws Exception {
		Application app = new Application();
		app.addCommand(new GenDoc("gendoc", 1));
		app.addCommand(new LS("ls", 0));
		app.addCommand(new CD("cd", 1));
		app.addCommand(new Login("login", 0));
		app.addCommand(new Logout("logout", 0));
		app.addCommand(new ShowUsers("showusers", 0));
		app.addCommand(new Dashboard("dashboard", 0));
		app.setStartupInfo("RZT Deployment Shell V0.02");
		app.setPrompt("RZT>");
		if (a.length > 0) {
			if (a.length != 2) {
				System.out
						.println("Invalid option. \nUsage: java -jar [jarfile.jar] --batch [batch filepath]");
				return;
			}
			if (a[0].equals("--batch") || a[0].equals("-b")) {
				String file = a[1];
				if (!new File(file).exists()) {
					System.out.println("Batch file: '" + file + "' not found.");
					return;
				}
				app.execBatch(file);
			} else {
				System.out
						.println("Invalid option '"
								+ a[0]
								+ "'. \nProvide '--batch or -b' option followed by batch filepath to run batch file");
			}
		} else {
			app.interpret();
		}
	}
}
